package com.cn.boot.student.entity;

import com.cn.boot.student.vo.PageParams;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Set;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "user", schema = "stu_manage_sys", catalog = "")
@ApiModel(value = "用户实体类")
public class UserEntity extends PageParams implements UserDetails {
    private int id;
    private String username;
    private String password;
    private String newPassword;
    private String sno;
    private String nickName;
    private String icon;
    private String sex;
    private Integer age;
    private String phone;
    private String email;
    private String className;
    private String degree;
    private String address;
    private String admissionDate;
    private String createTime;
    private String loginTime;
    private Integer status;
    private MultipartFile file;
    private String roleName;

    private String signStatus;
    private String lateTime;
    private String signTime;
    private String signUpdateTime;
    private String dailyStatus;

    private Set<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    /**
     * 账号是否过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账号是否被锁
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码是否过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账号是否可用
     * status==1就认为账号可用
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        if(this.status==null){
            return false;
        }
        return this.status==1;
    }
}
